package com.dyd.smco.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.dyd.smco.core.utils.response.ResponseUtil;
import com.dyd.smco.db.domain.SmartCommunityWelcome;
import com.dyd.smco.db.service.impl.WelcomeServiceImpl;
import com.dyd.smco.model.SmartCommunityWelcomeBody;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author ：duyd@segimail.com
 * @class ：com.dyd.smco.core.service.SmartCommunityWelcomeService
 * @date ：Created in 2025/8/7 15:11
 * @description：
 * @modified By：
 * @version:
 */
@Service
@CacheConfig(cacheNames = "smart_community_welcome")
public class SmartCommunityWelcomeService extends WelcomeServiceImpl {

    public Object validate(SmartCommunityWelcome welcome) {
        String img = welcome.getImg();
        if (Objects.isNull(img)) {
            return ResponseUtil.badArgument();
        }
        Integer rank = welcome.getRank();
        if (Objects.isNull(rank)) {
            return ResponseUtil.badArgument();
        }
        return null;
    }

    @Cacheable(sync = true)
    public List<SmartCommunityWelcome> querySelective(SmartCommunityWelcomeBody body) {
        QueryWrapper<SmartCommunityWelcome> wrapper = startPage(body);
        if (body.getIsDelete() != null) {
            wrapper.like(SmartCommunityWelcome.RANK , body.getIsDelete());
        }
        wrapper.orderByDesc(SmartCommunityWelcome.ID);
        return list(wrapper);
    }
}
